<template>
  <div class="app-container-custom">
    <el-row :gutter="10">
      <fold :span="5" :xs="24" :show.sync='sideshow'>
        <el-card shadow="never">
          <org-tree ref="orgTree" modelType="'dept','community','park','carp','vehicle'" @nodeClick="handleNodeClick" @firstNodeClick="handleNodeClick"/>
        </el-card>
      </fold>

      <el-col :span="sideshow ? 19 : 24" :xs="24">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain size="mini" @click="handleAddParking" v-hasPermi="['property:vehicle:add']">新增车辆</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain size="mini" @click="handleDelete" v-hasPermi="['property:vehicle:remove']">删除</el-button>
          </el-col>
        </el-row>
        <el-card shadow="never">
          <add-vehicle-form ref="addVehicleFrom" v-if="currentNode.modelType == 'carp'" :currentNode="currentNode"/>
          <add-from ref="addFrom" :currentNode="currentNode"/>
          <vehicle-from-main ref="vehicleMain" v-if="currentNode.modelType == 'vehicle'" :currentNode="currentNode"/>
          <parking-main res="parkingRefs" v-if="currentNode.modelType == 'park'" :currentNode="currentNode"/>
          <community-form res="communityRefs" v-if="currentNode.modelType == 'community'" :currentNode="currentNode"/>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {  delVehicle, exportVehicle } from "@/api/property/vehicle";
import  addVehicleForm from "./addVehicleForm"
import  addFrom from "./addForm"
import vehicleFromMain  from "./vehicleFrom/main"
import ParkingMain from "./parking/main";
import CommunityForm from "./community/form";
export default {
  name: "Vehicle",
  components:{addVehicleForm,addFrom,vehicleFromMain,ParkingMain,CommunityForm},
  data() {
    return {
        currentNode:{},
        sideshow:true
    };
  },
  methods: {
    handleNodeClick(node){
      this.currentNode = node;
    },
    handleAddParking(){
      if(this.currentNode.modelType=='carp'){
        this.$refs.addFrom.show({currentNode:this.currentNode,type:'ADD'})
      }else{
        this.msgWarning("请选择所属车位")
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = this.currentNode.id;
      if(this.currentNode.modelType=='vehicle'){
        this.$confirm('是否确认删除车辆管理编号为"' + this.currentNode.label + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delVehicle(ids);
        }).then(() => {
          this.$refs.orgTree.refresh()
          this.msgSuccess("删除成功");
        }).catch(() => {});
      }else {
        this.msgWarning("请选择所属车辆")
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有车辆管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportVehicle(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
  }
};
</script>
